import { requestClient } from '#/api/request';

export namespace ItemTypeAPI {
  export interface ListItem {
    code: number;
    data: [];
    msg: string;
  }
  export interface Datum {
    searchValue: null;
    createBy: any;
    createTime: Date;
    updateBy: null;
    updateTime: null;
    remark: string;
    params: any;
    itemTypeId: number;
    itemTypeCode: string;
    itemTypeName: string;
    parentTypeId: number;
    ancestors: string;
    itemOrProduct: any;
    orderNum: number;
    enableFlag: any;
    attr1: null;
    attr2: null;
    attr3: number;
    attr4: number;
    children: any[];
  }

  export interface ListItemData {
    msg: string;
    code: number;
    data: Datum[];
  }
}
export interface ItemTypeFormData {
  itemTypeId?: number; // 可选，用于编辑时
  itemTypeCode: string;
  itemTypeName: string;
  parentTypeId: number;
  itemOrProduct?: any;
  orderNum: number;
  enableFlag?: any;
  remark?: string;
  attr1?: any;
  attr2?: any;
  attr3?: number;
  attr4?: number;
}

// export const GetItemTypeList = (params?: {
//   itemTypeId?: number;
//   page?: number;
//   pageSize?: number;
// }) => {
//   return requestClient.get<AxiosResponse<ItemTypeAPI.ListItem>>(
//     '/mes/md/itemtype/list',
//     {
//       params,
//     },
//   );
// };

export const GetItemTypeList = (_p0?: any) => {
  return requestClient.get<ItemTypeAPI.ListItem>('/mes/md/itemtype/list');
};

// 删除
export const DeleteItemType = (id: number) => {
  return requestClient.delete<ItemTypeAPI.ListItemData>(
    `/mes/md/itemtype/${id}`,
  );
};

// 新增
export const AddItemType = (data: ItemTypeFormData) => {
  return requestClient.post<ItemTypeAPI.ListItemData>('/mes/md/itemtype', data);
};

// 修改
export const UpdateItemType = (data: ItemTypeFormData) => {
  return requestClient.put<ItemTypeAPI.ListItemData>(
    `/mes/md/itemtype/${data.itemTypeId}`,
    data,
  );
};
